package com.db.util;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

public class Netutil {
	
	// http://www.lottery.gov.cn/lottery_index_kj.json
	public static String getLast(String url) {
		HttpClient httpClient = HttpClientBuilder.create().build();
		// 创建Get请求
		HttpGet httpGet = new HttpGet(url);
		// 响应模型
		HttpResponse response = null;
		try {
			// 由客户端执行(发送)Get请求
			response = httpClient.execute(httpGet);
			// 从响应模型中获取响应实体
			HttpEntity responseEntity = response.getEntity();
			System.out.println("响应状态为:" + response.getStatusLine());
			if (responseEntity != null) {
				String rel = EntityUtils.toString(responseEntity);
				System.out.println("响应内容长度为:" + responseEntity.getContentLength());
				System.out.println("响应内容为:" + rel);
			    return rel;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			// 释放资源
		}
		return null;
	}
}
